home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Applications / gdbm-1.7.3 / source / systems.h < prev    next >
Text File  |  1994-05-22  |  4KB  |  181 lines

  1. /* systems.h - Most of the system dependant code and defines are here. */
  2.  
  3. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
  4.     Copyright (C) 1990, 1991, 1993  Free Software Foundation, Inc.
  5.  
  6.     GDBM is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2, or (at your option)
  9.     any later version.
  10.  
  11.     GDBM is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with GDBM; see the file COPYING.  If not, write to
  18.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     You may contact the author by:
  21.        e-mail:  phil@wwu.edu
  22.       us-mail:  Philip A. Nelson
  23.                 Computer Science Department
  24.                 Western Washington University
  25.                 Bellingham, WA 98226
  26.        
  27. *************************************************************************/
  28. #ifdef THINK_C
  29.  
  30. #include <memory.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <unix.h>
  35. #include <fcntl.h>
  36. #define L_SET SEEK_SET
  37. #define UNLOCK_FILE(dbf)    /* later !!!  */
  38. #define READLOCK_FILE(dbf)    lock_val = 0;
  39. #define WRITELOCK_FILE(dbf)    lock_val = 0;
  40. #define bcmp(d1, d2, n)     memcmp(d1, d2, n)
  41. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  42. #define alloca(m)        malloc(m)
  43. #define fsync(f)
  44. #define STATBLKSIZE 1024
  45. typedef int word_t;
  46. #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC));
  47.  
  48. #else
  49.  
  50. #ifdef __GNUC__
  51. #define alloca    __builtin_alloca
  52. #else    /* not __GNUC__ */
  53. #ifdef HAVE_ALLOCA_H
  54. #include <alloca.h>
  55. #endif    /* not HAVE_ALLOCA_H */
  56. #endif     /* not __GNUC__ */
  57.  
  58. /* Include all system headers first. */
  59. #if HAVE_SYS_TYPES_H
  60. #include <sys/types.h>
  61. #endif
  62. #include <stdio.h>
  63. #if HAVE_SYS_FILE_H
  64. #include <sys/file.h>
  65. #endif
  66. #include <sys/stat.h>
  67. #if HAVE_STDLIB_H
  68. #include <stdlib.h>
  69. #endif
  70. #if HAVE_STRING_H
  71. #include <string.h>
  72. #else
  73. #include <strings.h>
  74. #endif
  75. #if HAVE_UNISTD_H
  76. #include <unistd.h>
  77. #endif
  78. #if HAVE_FCNTL_H
  79. #include <fcntl.h>
  80. #endif
  81.  
  82. #ifndef SEEK_SET
  83. #define SEEK_SET        0
  84. #endif
  85.  
  86. #ifndef L_SET
  87. #define L_SET SEEK_SET
  88. #endif
  89.  
  90. /* Do we have flock?  (BSD...) */
  91.  
  92. #if HAVE_FLOCK
  93.  
  94. #ifndef LOCK_SH
  95. #define LOCK_SH    1
  96. #endif
  97.  
  98. #ifndef LOCK_EX
  99. #define LOCK_EX    2
  100. #endif
  101.  
  102. #ifndef LOCK_NB
  103. #define LOCK_NB 4
  104. #endif
  105.  
  106. #ifndef LOCK_UN
  107. #define LOCK_UN 8
  108. #endif
  109.  
  110. #define UNLOCK_FILE(dbf) flock (dbf->desc, LOCK_UN)
  111. #define READLOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_SH + LOCK_NB)
  112. #define WRITELOCK_FILE(dbf) lock_val = flock (dbf->desc, LOCK_EX + LOCK_NB)
  113.  
  114. #else
  115.  
  116. /* Assume it is done like System V. */
  117.  
  118. #define UNLOCK_FILE(dbf) \
  119.     {                    \
  120.       struct flock flock;            \
  121.       flock.l_type = F_UNLCK;        \
  122.       flock.l_whence = SEEK_SET;        \
  123.       flock.l_start = flock.l_len = 0L;    \
  124.       fcntl (dbf->desc, F_SETLK, &flock);    \
  125.     }
  126. #define READLOCK_FILE(dbf) \
  127.     {                    \
  128.       struct flock flock;            \
  129.       flock.l_type = F_RDLCK;        \
  130.       flock.l_whence = SEEK_SET;            \
  131.       flock.l_start = flock.l_len = 0L;    \
  132.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  133.     }
  134. #define WRITELOCK_FILE(dbf) \
  135.     {                    \
  136.       struct flock flock;            \
  137.       flock.l_type = F_WRLCK;        \
  138.       flock.l_whence = SEEK_SET;            \
  139.       flock.l_start = flock.l_len = 0L;    \
  140.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  141.     }
  142. #endif
  143.  
  144. /* Do we have bcopy?  */
  145. #if !HAVE_BCOPY
  146. #if HAVE_MEMORY_H
  147. #include <memory.h>
  148. #endif
  149. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  150. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  151. #endif
  152.  
  153. /* Do we have fsync? */
  154. #if !HAVE_FSYNC
  155. #define fsync(f) {sync(); sync();}
  156. #endif
  157.  
  158. /* Default block size.  Some systems do not have blocksize in their
  159.    stat record. This code uses the BSD blocksize from stat. */
  160.  
  161. #if HAVE_ST_BLKSIZE
  162. #define STATBLKSIZE file_stat.st_blksize
  163. #else
  164. #define STATBLKSIZE 1024
  165. #endif
  166.  
  167. /* Do we have ftruncate? */
  168. #if HAVE_FTRUNCATE
  169. #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
  170. #else
  171. #define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
  172. #endif
  173.  
  174. /* Do we have 32bit or 64bit longs? */
  175. #if LONG_64_BITS || !INT_16_BITS
  176. typedef int word_t;
  177. #else
  178. typedef long word_t;
  179. #endif
  180.  
  181. #endif